package qlsl.androiddesign.adapter.subadapter;

import java.util.List;

import qlsl.androiddesign.activity.baseactivity.BaseActivity;
import qlsl.androiddesign.adapter.baseadapter.BaseAdapter;
import qlsl.androiddesign.entity.commonentity.User;
import qlsl.androiddesign.entity.otherentity.PoemDynamic;
import qlsl.androiddesign.util.commonutil.ImageUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.qlsl.androiddesign.demo.R;

public class PoemDynamicAdapter extends BaseAdapter<PoemDynamic> {

	public PoemDynamicAdapter(BaseActivity activity, List<PoemDynamic> list) {
		super(activity, list);
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		convertView = getItemView(convertView, R.layout.griditem_poem_dynamic);

		ImageView iv_icon = getView(convertView, R.id.iv_icon);
		ImageView iv_head = getView(convertView, R.id.iv_head);
		TextView tv_content = getView(convertView, R.id.tv_content);
		TextView tv_tag = getView(convertView, R.id.tv_tag);
		TextView tv_type_name = getView(convertView, R.id.tv_type_name);
		TextView tv_store_num = getView(convertView, R.id.tv_store_num);
		TextView tv_comment_num = getView(convertView, R.id.tv_comment_num);
		TextView tv_name = getView(convertView, R.id.tv_name);
		TextView tv_level = getView(convertView, R.id.tv_level);

		PoemDynamic item = getItem(position);

		String petUrl = item.getPetUrl();
		String content = item.getContent();
		List<String> tags = item.getTags();
		String typeName = item.getTypeName();
		Integer storeNum = item.getStoreNum();
		Integer commentNum = item.getCommentNum();

		User user = item.getUser();

		ImageUtils.roundOri(activity, petUrl, iv_icon,
				R.drawable.app_icon_default);
		ImageUtils.circle(activity, user.getAvatar(), iv_head);

		tv_content.setText(content);

		StringBuffer sb_tag = new StringBuffer();
		for (int index = 0; index < tags.size(); index++) {
			String tag = tags.get(index);
			sb_tag.append(tag + "    ");
		}
		tv_tag.setText(sb_tag.toString());

		tv_type_name.setText(typeName);
		tv_store_num.setText(storeNum + "");
		tv_comment_num.setText(commentNum + "");

		tv_name.setText(user.getName());
		tv_level.setText("LV." + user.getLevel());

		return convertView;
	}
}
